define(function (t, e, n) {
    var $ = t("zepto");
    n.exports = $;
    (function ($) {
        $.fn.ylmap = function (option) {
            $.fn.ylmap.defaults = {
                detal: {
                    sign_name: "TXjiang",
                    contact_tel: 18624443174,
                    address: "天安门"
                },
                latitude: 39.915,
                longitude: 116.404,
                fnOpen: null,
                fnClose: null
            };
            option = $.extend({}, $.fn.ylmap.defaults, option);
            return this.each(function () {
                function e() {
                    if (0 >= $(".BDS").length) {
                        var e = document.createElement("script");
                        e.src = "http://api.map.baidu.com/api?v=1.4&callback=mapInit", e.className += "BDS", document.head.appendChild(e)
                    } else
                        b();
                    if (0 >= $(".BDC").length) {
                        var n = document.createElement("style");
                        n.type = "text/css", n.className += "BDC";
                        var a = i();
                        a ? (mapScale = 1, phoneScale = 1) : mapScale = phoneScale > 1 ? 1 : 1 / phoneScale, $(window).height();
                        var o = ".ylmap.open,.ylmap.mapOpen {height:100%;width:100%;background:#fff;}.ylmap img {max-width:initial!important;}.ylmap .tit { position:absolute; left:0; bottom:0; height:70px; width:100%; overflow: hidden; background:rgba(0,0,0,0.5); }.ylmap .tit p { margin-right:100px; }.ylmap .tit p a { position:relative; display:block; font-size:24px; color:#fff; height:70px; line-height:70px; padding-left:70px; }.ylmap .tit p a span { position:absolute; left:15px; top:15px; display:inline-block; width:40px;height:40px; }.ylmap .tit .close_map { display:none; position: absolute; bottom: 15px; right: 20px; width: 40px; height: 40px; margin-right:0; cursor:pointer; background-position: -100px -73px; }.ylmap .map_close_btn{position:absolute;top:10px;left:10px;display:none;width:80px;box-shadow:0 0 2px rgba(0,0,0,0.6) inset, 0 0 2px rgba(0,0,0,0.6);height:80px;border-radius:80%;color:#fff;background:rgba(230,45,36,0.8);text-align:center;line-height:80px;font-size:26px; font-weight:bold;cursor:pointer;}.ylmap.open .map_close_btn{display:block;}.ylmap.mapOpen .map_close_btn{display:block;}#BDMap {transform:scale(" + mapScale + ");-webkit-transform:scale(" + mapScale + ");}" + "#BDMap {width:100%;height:100%;}" + "#BDMap img{width:auto;height:auto;}" + ".ylmap.open .transitBtn{display:block;}" + ".ylmap.mapOpen .transitBtn{display:block;}" + ".transitBtn {display:none;position:absolute;z-index:3000;}" + ".transitBtn a{display:block;width:80px;box-shadow:0 0 2px rgba(0,0,0,0.6) inset, 0 0 2px rgba(0,0,0,0.6);height:80px;border-radius:80%;color:#fff;background:rgba(230,45,36,0.8);text-align:center;line-height:80px;font-size:24px; font-weight:bold}" + ".transitBtn.close {top:10px;right:10px;}" + ".transitBtn.bus {top:10px;right:110px;}" + ".transitBtn.car {top:110px;right:10px;}" + ".transitBtn.bus a{background:rgba(28,237,235,0.8);}" + ".transitBtn.car a{background:rgba(89,237,37,0.8);}" + "#transit_result{display:none;position:absolute;top:0;left:0;width:100%;height:100%;z-index:1000;overflow-y:scroll;}" + "#transit_result.open{display:block;}" + "#transit_result h1{font-size:26px!important;}" + "#transit_result div[onclick^='Instance']{background:none!important;}" + "#transit_result span{display:inline-block;font-size:20px;padding:0 5px;}" + "#transit_result table {font-size:20px!important;}" + "#transit_result table td{padding:5px 10px!important;line-height:150%!important;}" + ".infoWindow p{margin-bottom:10px;}" + ".infoWindow .window_btn .open_navigate{display:inline-block;padding:2px 6px; margin-right:10px;border:1px solid #ccc;border-radius:6px;text-align:center;cursor:pointer;}" + ".anchorBL{display:none!important;}";
                        n.innerHTML = o, document.head.appendChild(n)
                    }
                }
                function i() {
                    for (var t = navigator.userAgent, e = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"], n = !0, i = 0; e.length > i; i++)
                        if (t.indexOf(e[i]) > 0) {
                            n = !1;
                            break
                        }
                    return n;
                }
                var a, o, r, s, l = $(this), c = option.detal, u = option.latitude, d = option.longitude, h = option.fnClose, f = (option.fnOpen, l.hasClass("bigOpen")), p = null, g = null, m = null, v = null, x = $('<div id="BDMap" class="BDMap"></div>');
                l.append(x), l.append($('<div id="transit_result"></div>')), l.append($('<div class="tit"><p><a href="javascript:void(0)"><span class="css_sprite01"></span>' + c.address + "</a></p></div>")), l.append($('<p class="map_close_btn">退出</p>')), l.length > 0 && l.height(), f && l.find(".map_close_btn").css("display", "block"), $("#transit_result").length > 0 && "" != $("#transit_result").html() && $(".transitBtn").removeClass("hide");
                var b = function () {
                    l.size() > 0 && (o = new BMap.Map(x.attr("id")), r = new BMap.Point(d, u), s = new BMap.Marker(r), o.enableScrollWheelZoom(), o.enableInertialDragging(), o.centerAndZoom(r, 15), o.addOverlay(s), y(), s.addEventListener("click", function () {
                        y();
                    }), o.addEventListener("click", function () {
                        return !1;
                    }), o.addEventListener("zoomend", function () {
                        var t = o.getZoom();
                        o.centerAndZoom(r, t);
                    }))
                },
                        y = function () {
                            w(s, c);
                        },
                        w = function (e, n) {
                            var i = $('<div class="infoWindow"></div>');
                            n.contact_tel !== void 0 && i.append('<p class="tel"><a href="tel:' + n.contact_tel + '">' + n.contact_tel + "</a></p>"), i.append('<p class="address">' + n.address + "</p>"), i.append('<div class="window_btn"><span class="open_navigate open_bus" onclick="open_navigate(this)">公交</span><span class="open_navigate open_car" onclick="open_navigate(this)">自驾</span><span class="State"></span></div>');
                            var a = {width: 0, height: 0, title: " "}, r = new BMap.InfoWindow(i[0], a);
                            e.openInfoWindow(r, o.getCenter())
                        };
                open_navigate = function (e) {
                    p = $(e).hasClass("open_bus") ? "bus" : "car", navigate(), $(".infoWindow").find("span.State").html("正在定位您的位置！")
                }, navigate = function () {
                    window.navigator.geolocation ? window.navigator.geolocation.getCurrentPosition(handleSuccess, handleError, {timeout: 1e4}) : alert("sorry！您的设备不支持定位功能")
                }, handleError = function (e) {
                    var n;
                    switch (e.code) {
                        case e.TIMEOUT:
                            n = "获取超时!请稍后重试!";
                            break;
                        case e.POSITION_UNAVAILABLE:
                            n = "无法获取当前位置!";
                            break;
                        case e.PERMISSION_DENIED:
                            n = "您已拒绝共享地理位置!";
                            break;
                        case e.UNKNOWN_ERROR:
                            n = "无法获取当前位置!"
                    }
                    $(".infoWindow").find("span.State").length > 0 ? $(".infoWindow").find("span.State").html(n) : alert(n)
                };
                handleSuccess = function (e) {
                    var n = e.coords, i = n.latitude, a = n.longitude;
                    v = new BMap.Point(a, i), $(".infoWindow").find("span.State").html("获取信息成功，正在加载中！"), "bus" == p ? bus_transit() : self_transit(), f ? x.parent().addClass("mapOpen") : x.parent().addClass("open")
                };
                $(".map_close_btn").on("click", function () {
                    l.removeClass("mapOpen open"), h && h()
                });
                bus_transit = function () {
                    if (g && g.clearResults(), m && m.clearResults(), !v)
                        return alert("抱歉：定位失败！"), void 0;
                    $(".fn-audio").hide(), "function" == typeof loadingPageShow && loadingPageShow(), $(".infoWindow").find("span.State").html("正在绘制出导航路线");
                    var e = $("#transit_result") || $('<div id="transit_result"></div>');
                    e.appendTo(l), g = new BMap.TransitRoute(o, {renderOptions: {map: o, panel: "transit_result", autoViewport: !0}, onSearchComplete: searchComplete}), g.search(v, r)
                };
                self_transit = function () {
                    if (g && g.clearResults(), m && m.clearResults(), !v)
                        return alert("抱歉：定位失败！"), void 0;
                    $(".fn-audio").hide(), "function" == typeof loadingPageShow && loadingPageShow(), $(".infoWindow").find("span.State").html("正在绘制出导航路线");
                    var e = $("#transit_result") || $('<div id="transit_result"></div>');
                    e.appendTo(l), m = new BMap.DrivingRoute(o, {renderOptions: {map: o, panel: e.attr("id"), autoViewport: !0}, onSearchComplete: searchComplete}), m.search(v, r)
                };
                searchComplete = function (e) {
                    function n() {
                        var t;
                        t = window.event.touches[0].pageY, a = t
                    }
                    function i(e) {
                        e.stopPropagation(), e.preventDefault();
                        var n;
                        n = window.event.touches[0].pageY;
                        var i = $(this).scrollTop();
                        $(this).scrollTop(i + a - n), a = n
                    }
                    0 == e.getNumPlans() ? (alert("非常抱歉,未搜索到可用路线"), o.reset(), o.centerAndZoom(r, 15), y(), $("#transit_result").removeClass("open").hide(), $(".transitBtn").hide()) : ($("#transit_result").addClass("open"), $(".infoWindow").find("span.State").html(""), !$(".transitBtn").length > 0 && ($("#transit_result").after($('<p class="transitBtn close" onclick="transit_result_close()"><a href="javascript:void(0)">关闭</a></p>')), $("#transit_result").after($('<p class="transitBtn bus" onclick="bus_transit()"><a href="javascript:void(0)">公交</a></p>')), $("#transit_result").after($('<p class="transitBtn car" onclick="self_transit()"><a href="javascript:void(0)">自驾</a></p>'))), l.find(".close_map").show(), $("#transit_result").addClass("open"), $(".transitBtn").show(), $("#transit_result").on("touchstart", n), $("#transit_result").on("touchmove", i)), "function" == typeof loadingPageHide && loadingPageHide(), f || l.css({position: "fixed", top: "0", left: "0", height: "100%"}), $("#transit_result").hasClass("open") ? $(".close").find("a").html("关闭") : $(".close").find("a").html("打开")
                };
                transit_result_close = function () {
                    $("#transit_result").hasClass("open") ? ($("#transit_result").removeClass("open"), $(".close").find("a").html("打开")) : ($("#transit_result").addClass("open"), $(".close").find("a").html("关闭"))
                };
                window.mapInit = b, e();
            });
        };
    })($);
});